﻿using System;
using System.Collections;
using UnityEngine;
using UnityEngine.Profiling;
using Yoozoo.Gta.Common;

namespace Yoozoo.Core.Common
{
    [Serializable]
    public class ConstructTaskBase
    {
        [SerializeField]
        protected string _taskName;
        public string TaskName => _taskName;
        
        public ConstructTaskBase(string taskName)
        {
            _taskName = taskName;

        }

        public virtual bool Execute()
        {
            return true;
        }
    }
    
    [Serializable]
    public class LoadConstructTask : ConstructTaskBase
    {

        private Action _action;
        public int Type;

        public bool complete;
        
        public LoadConstructTask(string taskName,Action action,int type) : base(taskName)
        {
            Type = type;
            _action = action;
            complete = false;
        }

        public override bool Execute()
        {
            Profiler.BeginSample("LoadConstructTask." + _taskName);
            _action?.Invoke();
            ResidentHandler.Inst.GetFunction("G_Loading.constructTaskSuccess").Action(_taskName);
            complete = true;
            Profiler.EndSample();
            return true;
        }
    }

    // [Serializable]
    // public class LoadConstructCoroutine : ConstructTaskBase
    // {
    //     private IEnumerator _enumerator;
    //
    //     public LoadConstructCoroutine(string taskName,IEnumerator enumerator) : base(taskName)
    //     {
    //         _enumerator = enumerator;
    //     }
    //     
    //     public override bool Execute()
    //     {
    //         
    //         return false;
    //     }
    //     
    // }
    
}